from typing import List

import pandas as pd


def createDataframe(student_data: List[List[int]]) -> pd.DataFrame:
     # res = pd.DataFrame.from_records(student_data)
     # res.columns = ['student_id', 'age']
     # return res
     return pd.DataFrame(student_data, columns=['student_id', 'age'])

def getDataframeSize(players: pd.DataFrame) -> List[int]:
    # return list(players.shape)
    return [players.shape[0], players.shape[1]]

def selectFirstRows(employees: pd.DataFrame) -> pd.DataFrame:
    # return employees[:3]
    return employees.iloc[0:3]

def selectData(students: pd.DataFrame) -> pd.DataFrame:
    # return students[students['student_id'] == 101][['name', 'age']]
    # DataFrame.loc[行名称，列名称]
    # DataFrame.iloc[行索引，列索引]
    return students.loc[students['student_id']==101,['name','age']]

def createBonusColumn(employees: pd.DataFrame) -> pd.DataFrame:
    employees['bonus'] = employees['salary'] * 2
    return employees

def dropDuplicateEmails(customers: pd.DataFrame) -> pd.DataFrame:
    return customers.drop_duplicates(subset=['email'], keep='first')

def dropMissingData(students: pd.DataFrame) -> pd.DataFrame:
    # students.dropna(subset=['name'], inplace=True)
    # return students
    return students[students['name'].notna()]

def modifySalaryColumn(employees: pd.DataFrame) -> pd.DataFrame:
    employees['salary'] *= 2
    return employees

def renameColumns(students: pd.DataFrame) -> pd.DataFrame:
    students.rename(columns={'id': 'student_id', 'first': 'first_name', 'last': 'last_name', 'age': 'age_in_years'}, inplace=True)
    return students

def changeDatatype(students: pd.DataFrame) -> pd.DataFrame:
    return students.astype({'grade': 'int'})

def fillMissingValues(products: pd.DataFrame) -> pd.DataFrame:
    products['quantity'].fillna(0,inplace=True)
    return products

def concatenateTables(df1: pd.DataFrame, df2: pd.DataFrame) -> pd.DataFrame:
    return pd.concat([df1, df2], axis=0)

def pivotTable(weather: pd.DataFrame) -> pd.DataFrame:
    return weather.pivot(index='month', columns='city', values='temperature')

def meltTable(report: pd.DataFrame) -> pd.DataFrame:
    return report.melt(id_vars='product', var_name='quarter', value_name='sales')

def findHeavyAnimals(animals: pd.DataFrame) -> pd.DataFrame:
    return animals[animals['weight'] > 100].sort_values('weight', ascending=False)[['name']]